<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>寄生组合式继承</title>
</head>
<body>
    <script>
        //   function Parent (name){
        //      this.name = name
        //      this.color = ["red","yellow"]
        //   }
        //   Parent.prototype.getName = function(){
        //       console.log(this.name)
        //   }
        //   function  Child(name,age){
        //       Parent.call(this,name)
        //       this.age = age
        //   }
        // //   关键第三步
        // var F = function (){}
        // F.prototype = new Parent()
        // Child.prototype = new F()
        // let c1 = new Child("于可可",26)
        // let c2 = new Child("于青青",23)
        // ______________________________________________________________________________________________________
        function object(o){
           function F(){}
           F.prototype = o
           return new F()
        }
        function prototype(child,parent){
           var prototype = object(parent.prototype)
           prototype.constructor = child
           child.prototype = prototype
        }
         function Parent (name){
             this.name = name
             this.color = ["red","yellow"]
          }
          Parent.prototype.getName = function(){
              console.log(this.name)
          }
          function  Child(name,age){
              Parent.call(this,name)
              this.age = age
          }
          prototype(Child,Parent)
        let c1 = new Child("于可可",26)
        let c2 = new Child("于青青",23)
        c2.color.push("plum")
         console.log(c1,c2)
        //  child继承了所有的parent原型对象的属性和方法。目前来说，最完美的继承方法！
</script>
</body>
</html>